<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	<title>创建验证码</title>
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
    
    <!-- css -->
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
	<link rel="stylesheet" href="wx_assets/css/verifycode.css">
	
	<!-- scripts -->
	<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
	<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
</head>
<body>
	<div data-role="page">  
        <div data-role="header" class="page-header">  
            <h1>创建验证码</h1>  
        </div>
		
	<div data-role="fieldcontain" class="container">
		<label for="event">奖品名称：</label>
		<input type="text" name="name" id="event" data-mini="true"/>
		<label for="count">奖品数量：</label>
		<input type="text" name="count" id="count" data-mini="true"/>
		<a href=""  id="button-create" data-role="button" >创建</a>
	</div>
		
<script type="text/javascript">
	var hrefParamsArray = null;
	
	window.onload = function onLoad() {
		hrefParamsArray = GetSessionIdFromHref(window.location.search);
	}
	
	//获取当前页面customerId,userName
	//?customerId=XXX&userName=XXX&module=XXX
	function GetSessionIdFromHref(search){
		
	　　	var args = search.substring(1); 
	　　	var retval = new Array(); 
		args = args.split("&"); 
　　		for(var i = 0; i < args.length; i ++){ 
　　			str = args[i]; 
　　			var arg = str.split("="); 
　　			if(arg.length <= 1) continue; 
　　			if(arg[0] == 'customerId') {
　　				retval["customerId"] = arg[1]; 
　　				//return retval; 
　　			}else if(arg[0] == 'userName'){
　　				retval["userName"] = arg[1]; 
　　			}
　　		} 
　　		return retval; 
　　}
	
	$("#button-create").click(function(){
		var baseUrl =  '{$Think.config.SERVER_HOST}';
		var urlString = baseUrl + 'call.json/?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
		$.ajax({
			url : urlString,  
			type : 'POST',
			data : { 
				'module': 'verifyCode',
		        'method' : 'create',
		        'params' : '{"reward":"' + $('#event').val() + '","count":' + $('#count').val() + '}'
		    },
			dataType : 'json',
			async: false
		}).done(function(data) { 
			if(data.code == 0){
				$('#event').val('');
				$('#count').val('');
				var baseUrl =  '{$Think.config.SERVER_HOST}';
				var urlString = baseUrl + 'call.html?module=verifyCode&method=verifycode_list&customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
				window.open(urlString);
			} else{
				alert("错误: 添加失败");
			}
		}).error( function(XMLHttpRequest, textStatus, errorThrown) {
			alert("错误: " + textStatus);
	    });
	});
</script>
</body>


</html>